# -*- coding: utf-8 -*-
import time
from selenium import webdriver
import unittest
import xlrd
from venv1.Page.loginPage import loginPage
from venv1.publicModule.login import login
from venv1.Page.inqueryPage import inqueryPage
from venv1.publicModule.inquery import inquery
from venv1.Page.policyIfmComPage import policyIfmComPage
from venv1.publicModule.policyIfmCom import policyIfmCom
from venv1.publicModule.UWfllowup import UWfllowup
from venv1.publicModule.UWdeal import UWdeal
from venv1.Page.inqueryPage import inqueryPage
from venv1.publicModule.inquery import inquery
from venv1.publicModule.Recheck import Recheck
from venv1.publicModule.test import test
from venv1.Include.sendEmail import SendMail


class UW_Case(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(10)
        self.driver.maximize_window()
        self.driver.get("http://10.22.26.74:8080/dist/index.html#/")
        time.sleep(2)
        self.loginPage = loginPage(self.driver)
        self.login = login(self.driver)
        self.inqueryPage=inqueryPage(self.driver)
        self.inquery=inquery(self.driver)
        self.policyIfmComPage = policyIfmComPage(self.driver)
        self.policyIfmCom = policyIfmCom(self.driver)
        self.UWfllowup = UWfllowup(self.driver)
        self.UWdeal = UWdeal(self.driver)
        self.Recheck = Recheck(self.driver)

    def test01(self):
        filename= r'..\data\testdata.xlsx'
        excel_open=xlrd.open_workbook(filename)
        table=excel_open.sheet_by_name('Sheet1')
        # rows=table.nrows

        row_content=table.row_values(2)
        username=row_content[74]
        password=row_content[75]
        login.login(self,username,password)
    def test02(self):
        filename = r'..\data\testdata.xlsx'
        excel_open = xlrd.open_workbook(filename)
        table = excel_open.sheet_by_name('Sheet1')
        rows = table.nrows
        row = 1
        for i in range(2, rows):
            row_content = table.row_values(i)
            PolicyNo = row_content[76]
            ProjectCode = row_content[78]
            UWidea = row_content[79]
            State=row_content[77]
            # username = row_content[0]
            # password = row_content[1]
            # login.login(self, username, password)
            if PolicyNo=='':
                pass
            else:
                if State=='承保':
                    # 分配任务
                    inquery.Assign_To(self,PolicyNo)
                    time.sleep(2)
                    # 信息确认
                    policyIfmCom.PolicyIfm_comfire(self, PolicyNo)
                    time.sleep(2)
                    # 核保待处理（承保）
                    UWfllowup.UW_fllowup(self, PolicyNo)
                    time.sleep(2)
                    # 核保结论
                    # inquery.UWdecision(self, PolicyNo)
                elif State=='拒保':
                    # 分配任务
                    inquery.Assign_To(self, PolicyNo)
                    time.sleep(2)
                    #  保单信息确认下发问题件
                    policyIfmCom.drop(self, PolicyNo, ProjectCode)
                    time.sleep(2)
                    #  核保待处理
                    UWdeal.UWdeal(self, PolicyNo, UWidea)
                    time.sleep(2)
                    #  核保复核
                    Recheck.Recheck(self, PolicyNo)
                    time.sleep(5)
                    # 核保结论

                elif State=='不处理':
                    print('不做处理')
                else:
                    print('error!')
                if State=='承保' or State=='拒保':
                    row = row + 1
                    inquery.UWdecision(self, PolicyNo, row)
                else:
                    pass
    def test03(self):
        test().test()
    def test04(self):
        localtime = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
        m = SendMail(
            username='1136019175@qq.com',
            passwd='TANjianmin0621',
            recv=['crystal.tan@fwd.com'],
            title=localtime,
            content='本次smart建单执行的结果见附件',
            file="..\\Result\\" + localtime + ".xls",
            ssl=True, )
        m.send_mail()

if __name__ == '__main__':

    unittest.main()
    # suite = unittest.TestLoader.loadTestsFromTestCase(Case)
    # unittest.TextTestRunner().run(suite)

